package com.sam;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * Servlet Filter implementation class MyFilter
 */
public class MyFilter implements Filter {

    /**
     * Default constructor. 
     */
    public MyFilter() {
        // TODO Auto-generated constructor stub
    }


	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		// place your code here

		// pass the request along the filter chain
		//response.setCharacterEncoding("UTF-8");
		//PrintWriter out = response.getWriter();
		//String userid = request.getParameter(userid);
		//String uid = (String) request.getAttribute("userid");
		
		System.out.println("HELLO");
		System.out.println("進入之前");
		
		if (request.getCharacterEncoding()==null){
			request.setCharacterEncoding("UTF-8");
		}
		response.setCharacterEncoding("UTF-8");
		String name = "測試";
		name = new String(name.getBytes(), "ISO-8859-1");
				
		chain.doFilter(request, response);
		System.out.println("進入之後");
		
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}
}
